package com.homework.work04;

public class Clock {
    public static void main(String[] args) {
        Clock01 clock = new Clock01(40,59,10);
        while(true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            clock.second01();
            System.out.println("时钟："+clock.getHour()+":"+clock.getMinute()+":"+clock.getSecond());
        }
    }
}

class Clock01{
    private int second;
    private int minute;
    private int hour;

    public Clock01(int second, int minute, int hour) {
        if (!(second>0 && second<60)){
            System.out.println("秒的时间输入有误，请输入1-59");
            return;
        }
        if (!(minute>0 && minute<60)){
            System.out.println("分钟的时间输入有误，请输入1-59");
            return;
        }
        if (!(hour>0 && hour<24)){
            System.out.println("小时的时间输入有误，请输入1-23");
            return;
        }
        this.second = second;
        this.minute = minute;
        this.hour = hour;
    }

    public void second01(){
        second++;
        if (second == 60){
            minute++;
            second = 0;
        }

        if (minute == 60){
            hour++;
            minute = 0;
        }

        if (hour == 24){
            hour = 0;
        }
    }

    public int getSecond() {
        return second;
    }

    public int getMinute() {
        return minute;
    }

    public int getHour() {
        return hour;
    }
}
